<?php
use App\Task;
use Illuminate\Http\Request;
/*
|--------------------------------------------------------------------------
| Application Routes
|--------------------------------------------------------------------------
|
| Here is where you can register all of the routes for an application.
| It's a breeze. Simply tell Laravel the URIs it should respond to
| and give it the controller to call when that URI is requested.
|
*/

/**
 * Display All Tasks
 */
Route::get('/', ['as' => 'sssssaaaaa',function () {
	echo Route::currentRouteName();
    $tasks = Task::orderBy('created_at', 'desc')->get();
	
    return view('tasks', [
        'tasks' => $tasks
    ]);
	}
]);

//发邮件
Route::get('mail/send','MailController@send');

Route::get('/tasks', 'TaskController@index');
Route::post('/task', 'TaskController@store');
Route::delete('/task/{task}', 'TaskController@destroy');

/**
 * Add A New Task
 */
/*Route::post('/task', function (Request $request) {
    $validator = Validator::make($request->all(), [
        'name' => 'required|max:255',
    ],[
		'name.required'=>'请输入name'
	]);

    if ($validator->fails()) {
        return redirect('/')
            ->withInput()
            ->withErrors($validator);
    }

    $task = new Task();
    $task->name = $request->name;
    $task->save();
    return redirect('/');
});

/**
 * Delete An Existing Task

Route::delete('/task/{id}', function ($id) {
    Task::findOrFail($id)->delete();
    return redirect('/');
});*/


Route::get('testCsrf',function(){
    $csrf_field = csrf_field();
    $token = csrf_token();
    echo $token;
    $html = <<<GET
        <form method="POST" action="/testCsrf">
        $csrf_field
            <input type="submit" value="Test"/>
        </form>
GET;
    return $html;
});

Route::post('testCsrf',function(){
    return 'Success!';
});

Route::get('foo', function () {
    $data = [
        'id'=>1,
        'name'=>'xiaoming'
    ];
    return response()->json($data,422);
});

Route::get('user/{id}/profile', ['as' => 'profile', function($id) {
    return 'profile'.$id;
}]);

Route::get('user/{name}', function ($name) {
    return $name;
})->where('name', '[A-Za-z]+');

Route::get('user/{id}/username/{username}', function ($id,$username) {
    return 'User '.$id.'username '.$username;
});


Route::resource('post','PostController');

Route::controller('request', 'RequestController');
Route::controller('test', 'TestController');

Route::controller('table','TableController');
Route::controller('test','TestController');
Route::resource('orm', 'OrmController');


// 认证路由...
Route::get('auth/login', 'Auth\AuthController@getLogin');
Route::post('auth/login', 'Auth\AuthController@postLogin');
Route::get('auth/logout', 'Auth\AuthController@getLogout');
// 注册路由...
Route::get('auth/register', 'Auth\AuthController@getRegister');
Route::post('auth/register', 'Auth\AuthController@postRegister');
Route::get('profile','UserController@profile');
// 发送密码重置链接路由
Route::get('password/email', 'Auth\PasswordController@getEmail');
Route::post('password/email', 'Auth\PasswordController@postEmail');

// 密码重置路由
Route::get('password/reset/{token}', 'Auth\PasswordController@getReset');
Route::post('password/reset', 'Auth\PasswordController@postReset');

Route::get('auth/github', 'Auth\AuthController@redirectToProvider');
Route::get('auth/github/callback', 'Auth\AuthController@handleProviderCallback');



$api = app('api.router');
$api->version('v1', function ($api) {
    $api->get('users/{id}', 'App\Api\V1\Controllers\UserController@show');
//    $api->get('users/{id}', ['as' => 'users.index', 'uses' => 'App\Api\V2\Controllers\UserController@show']);
});

$api->version('v2', function ($api) {
    $api->get('users/{id}', 'App\Api\V2\Controllers\UserController@show');
});

Route::get('excel/export','ExcelController@export');
Route::get('excel/import','ExcelController@import');

Route::get('mail/sendReminderEmail/{id}','MailController@sendReminderEmail');

